<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use App\Models\TenantUser;
use App\Models\Tenant;

class TenantUserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->command?->info('开始创建租户用户测试数据...');

        // 获取第一个租户
        $tenant = Tenant::first();

        if (! $tenant) {
            $this->command?->warn('TenantUserSeeder: 未找到租户数据，建议先运行 TenantSeeder。');
            return;
        }

        // 创建租户管理员
        TenantUser::create([
            'tenant_id' => $tenant->id,
            'username' => 'tenant_admin',
            'email' => 'admin@tenant.local',
            'name' => '租户管理员',
            'phone' => '13800138001',
            'password' => '123456',
            'role' => 'admin',
            'status' => 'active',
            'email_verified_at' => now(),
            'created_by' => null
        ]);
        $this->command?->info('创建租户管理员: tenant_admin');

        // 创建普通操作员
        TenantUser::create([
            'tenant_id' => $tenant->id,
            'username' => 'operator01',
            'email' => 'operator@tenant.local',
            'name' => '操作员',
            'phone' => '13800138002',
            'password' => '123456',
            'role' => 'operator',
            'status' => 'active',
            'email_verified_at' => now(),
            'created_by' => null
        ]);
        $this->command?->info('创建租户操作员: operator01');

        $this->command?->info('租户用户测试数据创建完成！');
        $this->command?->info('登录信息:');
        $this->command?->info('管理员 - 用户名: tenant_admin, 密码: 123456');
        $this->command?->info('操作员 - 用户名: operator01, 密码: 123456');
    }
}
